/************************************************************
** @Description: FYKJ_Admin
** @Author: dabin
** @Date:   2021-03-02 21:21
** @Last Modified by:   dabin
** @Last Modified time: 2021-03-02 21:21
*************************************************************/
package main

import (
	_ "FYKJ_Admin/controllers/login"
	_ "FYKJ_Admin/models/auth"
	_ "FYKJ_Admin/models/my_center"
	_ "FYKJ_Admin/models/caiwu"
	_ "FYKJ_Admin/models/news"
	_ "FYKJ_Admin/routers"
	"FYKJ_Admin/utils"
	"fmt"
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/logs"
	"github.com/astaxie/beego/orm"
	_ "github.com/go-sql-driver/mysql"
)

// 连接数据库配置
func init() {
	username := beego.AppConfig.String("username")
	pwd := beego.AppConfig.String("pwd")
	host := beego.AppConfig.String("host")
	port := beego.AppConfig.String("port")
	db := beego.AppConfig.String("db")
	//mysql 连接字符串拼接
	// username:pwd@tcp(ip:port)/db?charset=utf8&loc=Local
	dataSource := username + ":" + pwd + "@tcp(" + host + ":" + port + ")/" + db + "?charset=utf8mb4&loc=Local"
	// 注册数据库驱动
	orm.RegisterDriver("mysql", orm.DRMySQL)
	// 注册两个数据库连接
	orm.RegisterDataBase("default", "mysql", dataSource)

	ret :=fmt.Sprintf("数据库连接信息，连接信息：host:%s|port:%s|db:%s,username:%s|pwd:%s",host,port,db,username,pwd)
	logs.Info(ret)
}

func main() {
	//先执行orm初始化命令// 命令行支持orm命令的参数
	orm.RunCommand()
	//开启session
	beego.BConfig.WebConfig.Session.SessionOn = true
	//未登入请求拦截
	beego.InsertFilter("/main/*", beego.BeforeRouter, utils.LoginFilter)

	//日志收集
	logs.SetLogger(logs.AdapterMultiFile,`{"filename":"logs/fy.log","separate":["error","info"]}`)
	logs.SetLogFuncCallDepth(3)
	//静态文件路径设置
	beego.SetStaticPath("/upload","upload")
	//启动beego项目
	beego.Run()

}
